﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using DotSpatial.Controls;
using DotSpatial.Data;
using DotSpatial.Topology;

using HaGisPack;

namespace TestWindow
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();

            Gis = new GisManager(this.map1 );

            Gis.MFSys.ShapeAdded += new ShapeHandler(MFSys_ShapeAdded);
            Gis.MFSys.ShapeChanged += new  ShapeHandler(MFSys_ShapeChanged);
            Gis.MFSys .ShapeRemoved +=new ShapeHandler(MFSys_ShapeRemoved);

            Gis.UISys.Tree = this.treeView1;

            Gis.UISys.PropertyGrid  = this.propertyGrid1;
        }

        void MFSys_ShapeChanged(FShape shp)
        {
            this.Gis.LayerSys.ChangeShape(shp);
        }

        void MFSys_ShapeAdded(FShape shp)
        {
           
            Rect dlgdese = new Rect();
            if (dlgdese.ShowDialog() == DialogResult.OK)
            {
                shp.descString = dlgdese.Descrip;
            }

            this.Gis.LayerSys.AddShape(shp);
        }

        void MFSys_ShapeRemoved(FShape shp)
        {
            this.Gis.LayerSys.RemoveShape(shp);
        }

        GisManager Gis;

        private void map1_Load(object sender, EventArgs e)
        {



          

        }

        private void Form2_Load(object sender, EventArgs e)
        {


          

       

        }

        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            Gis.NewProj(@"c:\test1\");

            //FEPolygonLayer PloygonRectanle = new FEPolygonLayer("Rectanle");
            //Gis.LayerSys.AddLayer(PloygonRectanle);

            //FEPolygonLayer PolygonCircle = new FEPolygonLayer("Circle");
            //Gis.LayerSys.AddLayer(PolygonCircle);

            //FEPolygonLayer PolygonSquare = new FEPolygonLayer("Square");
            //Gis.LayerSys.AddLayer(PolygonSquare);

            //FEPointLayer PointLayer = new FEPointLayer("Point");
            //Gis.LayerSys.AddLayer(PointLayer);

            //FELineLayer LineLayer = new FELineLayer("Line");
            //Gis.LayerSys.AddLayer(LineLayer);

            //FEPolygonLayer PolygonLayer = new FEPolygonLayer("Polygon");
            //Gis.LayerSys.AddLayer(PolygonLayer);

            map1.ZoomToMaxExtent();
        }

        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            Gis.OpenProj(@"c:\test1\");
        }

        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            Gis.SaveProj();
        }

        private void toolStripButton4_Click(object sender, EventArgs e)
        {
            Gis.CloseProj();
        }

        private void toolStripButton5_Click(object sender, EventArgs e)
        {

            FEPolygonLayer PloygonRectanle = new FEPolygonLayer("Rectanle");
            PloygonRectanle.descString = "矩形";

            FEPolygonLayer PolygonCircle = new FEPolygonLayer("Circle");
            PolygonCircle.descString = "圆形";

            FEPolygonLayer PolygonSquare = new FEPolygonLayer("Square");
            PolygonSquare.descString = "正方形";

            FEPointLayer PointLayer = new FEPointLayer("Point");
            PointLayer.descString = "点";


            FEPolygonLayer PolygonLayer = new FEPolygonLayer("Polygon");
            PolygonLayer.descString = "多边形";

            FDGridLayer gridLayer = new FDGridLayer("grid");
            gridLayer.descString = "网格";

            FELineLayer LineLayer = new FELineLayer("Line");
            LineLayer.descString = "线";

            FCompoundLayer cl = new FCompoundLayer("HA");
            cl.descString = "环安科技有限公司";

            FBitmapLayer bitmaplayer = new FBitmapLayer("bitmap1", @"E:\Picture\壁纸\000.jpg", new PointF(0, 0), new PointF(1024, 768)
            , new PointF(0, 0), new PointF(300, 300));

            //Gis.LayerSys.AddLayer(bitmaplayer);
          

            //cl.AddChild(PloygonRectanle);
            //cl.AddChild(PolygonCircle);
            //cl.AddChild(PolygonSquare);
            //cl.AddChild(PointLayer);
            //cl.AddChild(PolygonLayer);
            //cl.AddChild(gridLayer);
            //cl.AddChild(LineLayer);
            //Gis.LayerSys.AddLayer(cl);

            Gis.LayerSys.AddLayer(gridLayer);
            Gis.LayerSys.AddLayer(PloygonRectanle);
            Gis.LayerSys.AddLayer(PolygonCircle);
            Gis.LayerSys.AddLayer(PolygonSquare);
            Gis.LayerSys.AddLayer(PointLayer);
            Gis.LayerSys.AddLayer(PolygonLayer);
           
            Gis.LayerSys.AddLayer(LineLayer);


            //先测试其中的一部分功能


            

            //Gis.LayerSys.AddLayer(gridLayer);

            ////=============================================================
            //FDContourLayer contourlayer = new FDContourLayer("contour");

            //contourlayer.descString = "等值线";

            //Gis.LayerSys.AddLayer(contourlayer);

           
            //cl.AddChild(contourlayer);


            map1.ZoomToMaxExtent();

            

        }

        private void toolStripButton6_Click(object sender, EventArgs e)
        {
            Gis.LayerSys.SetCurrentLayer("Point");
            Gis.MFSys.UseFunctionTool(FunctionTool .POINT );
        }

        private void toolStripButton7_Click(object sender, EventArgs e)
        {
            Gis.LayerSys.SetCurrentLayer("Line");
            Gis.MFSys.UseFunctionTool(FunctionTool.lINE );
        }

        private void toolStripButton8_Click(object sender, EventArgs e)
        {
            Gis.LayerSys.SetCurrentLayer("Polygon");
            Gis.MFSys.UseFunctionTool(FunctionTool.FourPtPOLYGON);
        }

        private void toolStripButton9_Click(object sender, EventArgs e)
        {
            Gis.LayerSys.SetCurrentLayer("Rectanle");
            Gis.MFSys.UseFunctionTool(FunctionTool.RECTANGLE );
        }

        private void toolStripButton10_Click(object sender, EventArgs e)
        {
            Gis.LayerSys.SetCurrentLayer("Circle");
            Gis.MFSys.UseFunctionTool(FunctionTool.CIRCLE );
        }

        private void toolStripButton11_Click(object sender, EventArgs e)
        {
            Gis.LayerSys.SetCurrentLayer("Square");
            Gis.MFSys.UseFunctionTool(FunctionTool.SQUARE );
        }

        private void toolStripButton12_Click(object sender, EventArgs e)
        {
            //选择
            //this.map1.FunctionMode = FunctionMode.None;
            //this.map1.FunctionMode = FunctionMode.Select;

            Gis.MFSys.UseFunctionTool(FunctionTool.SELECT);
        }

        private void toolStripButton13_Click(object sender, EventArgs e)
        {
            Gis.MFSys.UseFunctionTool(FunctionTool.MOVE);
        }

        private void toolStripButton14_Click(object sender, EventArgs e)
        {
            FDContourLayer contourlayer = new FDContourLayer("contour");
            contourlayer.descString = "等值线";

            Gis.LayerSys.AddLayer(contourlayer);

            ContourLine CL;


            //先把数据赋好值
            for (int i = 0; i < 23; i++)
            {
                CL = new ContourLine();
                CL.ContourLineValue = 33 + i * 2;
                contourlayer.ContourLineList.Add(CL);
            }

            DrawContour.Contours cons = new DrawContour.Contours();
            cons = cons.Open(@"D:\ContourLine.SSS");

            contourlayer.SetContours(cons);

            //有了数据就可以画等值线了
            contourlayer.DrawContourLines();

            //等值线画好了，再设置颜色
            List<System.Drawing.Color> fillcolor = new List<Color>();           
            fillcolor.Add(Color.Green);
            fillcolor.Add(Color.Yellow);
            fillcolor.Add(Color.Red);
            fillcolor.Add(Color.Aquamarine);

            contourlayer.LineFillColorArray = fillcolor.ToArray();

           

          

        }

        private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {

        }

        private void toolStripButton15_Click(object sender, EventArgs e)
        {
            this.map1.FunctionMode = FunctionMode.None;
            this.map1.FunctionMode = FunctionMode.Pan;
        }

        private void toolStripButton16_Click(object sender, EventArgs e)
        {
            foreach (FLayer lay in this.Gis.LayerSys.Layers.Values)
            {
                (lay.ILayer as DotSpatial.Symbology.IFeatureLayer).Selection.Clear(); 
 
            }
        }

        private void toolStripButton17_Click(object sender, EventArgs e)
        {
            this.map1.ZoomToMaxExtent();
        }



    }
}
